package Three;

public class ArrayIntegerStack implements IntegerStack {
	int n;
	int head = 0;
	Integer[] values;

	public ArrayIntegerStack(int n) {
		this.n = n;
		values = new Integer[n];
	}

	public Integer push(Integer item) {
		if (item == null || n == head)
			return null;
		else {
			values[head++] = item;
			return item;
		}
	}

	@Override
	public Integer pop() {
		if (head == 0) {
			return null;
		} else {
			return values[--head];
		}

	}

	@Override
	public Integer peek() {
		if (head == 0)
			return null;
		else
			return values[head - 1];

	}

	@Override
	public boolean empty() {
		if (head == 0)
			return true;
		else
			return false;
	}

	@Override
	public int size() {
		return head;
	}

}
